package com.epfresh.supplier.activity;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.epfresh.api.entity.RequestEntitySupply;
import com.epfresh.api.entity.RequestTag;
import com.epfresh.api.entity.ResponseEntity;
import com.epfresh.api.entity.TagPager;
import com.epfresh.api.global.BaseActivity;
import com.epfresh.api.global.BaseApplication;
import com.epfresh.api.global.DataManager;
import com.epfresh.api.global.MessageCentre;
import com.epfresh.api.http.HttpRequest;
import com.epfresh.api.http.OnRequestListener;
import com.epfresh.api.utils.CashierInputFilter;
import com.epfresh.api.utils.T;
import com.epfresh.api.widget.list.LoadMoreListView;
import com.epfresh.api.widget.ptr.PtrDefaultHandler;
import com.epfresh.api.widget.ptr.PtrFrameLayout;
import com.epfresh.api.widget.ptr.PtrHandler;
import com.epfresh.api.widget.ptr.PtrMdFrameLayout;
import com.epfresh.supplier.R;
import com.epfresh.supplier.adapter.OfferAdapter;
import com.epfresh.supplier.dialog.OfferReasonListDialog;
import com.epfresh.supplier.entity.*;
import com.google.gson.Gson;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.epfresh.api.utils.*;
/*报价*/
public class OfferListActivity extends BaseActivity implements LoadMoreListView.IXListViewListener,OfferAdapter.WriteContent{
    private LoadMoreListView mListView;
    private View ll_hint,iv_offer_hint_close;
    private TextView tv_offer_hint;


    private ArrayList<OfferListEntity.ContentBean.ProductListBean> list;
    Context mContext;
    OfferAdapter adapter;
    protected View mainView;
    protected View vException;
    protected TextView tvExceptionDescription;
    protected ImageView ivExceptionIcon;
    private ProgressBar pb;
    private int requestSucceedCount = 0;
    private int PAGE_SIZE = 5;
    private TagPager tagPager = new TagPager();

    public boolean isActivityVisible;

    @Override
    protected void onResume() {
        super.onResume();
        isActivityVisible = true;
        MessageCentre.getInstance().offerListActivity = this;
    }
    public void updateTopHint(String hint){
        tv_offer_hint.setText(hint);
        ll_hint.setVisibility(View.VISIBLE);
        ll_hint.postDelayed(new Runnable() {
            @Override
            public void run() {
                ll_hint.setVisibility(View.GONE);
            }
        }, 5000);

    }
    @Override
    protected void onPause() {
        super.onPause();
        isActivityVisible = false;
        MessageCentre.getInstance().offerListActivity = null;
    }



    @Override
    public void write(int position, String content){
        if (TextUtils.isEmpty(content)) {
            return;
        }
        try {
            Double.parseDouble(content);//损失
        } catch (Exception ex) {
            return;
        }
        list.get(position).setPriceNow(new BigDecimal(Double.parseDouble(content)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
        //adapter.notifyDataSetChanged();
    }
    private BigDecimal getUnit(Double price){
        BigDecimal unit;
        if(price*10%1>0){
            unit = new BigDecimal(0.01);
        }else if(price*10%10>0){
            unit = new BigDecimal(0.1);
        }else{
            unit = new BigDecimal(1);
        }
        return unit;
    }
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        //list = new ArrayList<MinusRecordBean.ContentBean.ListBean>();
        list = new ArrayList<OfferListEntity.ContentBean.ProductListBean>();

        mListView.setPullLoadEnable(true); // 设置可滑动
        mListView.setXListViewListener(this);// 设置滑动监听器
        mContext = this;
        adapter = new OfferAdapter(this, list);
        adapter.setWriteContent(this);
        adapter.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                Log.e("activity________",""+position);

                if(view.getId()==R.id.tv_offer_sure){
                    OfferListEntity.ContentBean bean = (OfferListEntity.ContentBean)view.getTag(R.id.item_key_status);
                    postSubmit(bean);
                }else if(view.getId()==R.id.iv_offer_close){
                    OfferListEntity.ContentBean.ProductListBean bean = (OfferListEntity.ContentBean.ProductListBean)view.getTag(R.id.item_key_status);
                    Log.e("___dia_________before",""+bean.getId());
                    openReasonDialog(bean);
                }else if(view.getId()==R.id.iv_offer_add){
                    OfferListEntity.ContentBean.ProductListBean goods = (OfferListEntity.ContentBean.ProductListBean)view.getTag(R.id.item_key_status);
                    BigDecimal unit = getUnit(goods.getUnitPrice());
                    goods.setPriceNow(unit.add(new BigDecimal(goods.getPriceNow())).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
                    if(goods.getPriceNow().doubleValue()>9999.99){
                        toast("价格不能大于9999.99");
                        goods.setPriceNow(9999.99);
                    }
                }else if(view.getId() == R.id.iv_offer_minus){
                    OfferListEntity.ContentBean.ProductListBean goods = (OfferListEntity.ContentBean.ProductListBean)view.getTag(R.id.item_key_status);
                    BigDecimal unit = getUnit(goods.getUnitPrice());
                    if((new BigDecimal(goods.getPriceNow()).subtract(unit)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue()<=0){
                        toast("价格不能小于0");
                        return;
                    }
                    goods.setPriceNow((new BigDecimal(goods.getPriceNow()).subtract(unit)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
                }else if(view.getId() == R.id.tv_offer_price){
                    OfferListEntity.ContentBean.ProductListBean goods = (OfferListEntity.ContentBean.ProductListBean)view.getTag(R.id.item_key_status);
                    openDialog(goods);
                }
                else if(view.getId()==R.id.tv_offer_time_limit_1){
                    OfferListEntity.ContentBean.ProductListBean bean = (OfferListEntity.ContentBean.ProductListBean)view.getTag(R.id.item_key_status);
                    if(bean.getFather().getExpiredMinSelect().equals(bean.getFather().getFather().getExpiredMin().get(0)))
                        return;
                    else {
                        bean.getFather().setExpiredMinSelect(bean.getFather().getFather().getExpiredMin().get(0));
                    }
                }
                else if(view.getId()==R.id.tv_offer_time_limit_2){
                    OfferListEntity.ContentBean.ProductListBean bean = (OfferListEntity.ContentBean.ProductListBean)view.getTag(R.id.item_key_status);
                    if(bean.getFather().getExpiredMinSelect().equals(bean.getFather().getFather().getExpiredMin().get(1)))
                        return;
                    else {
                        bean.getFather().setExpiredMinSelect(bean.getFather().getFather().getExpiredMin().get(1));
                    }
                }
                else if(view.getId()==R.id.tv_offer_time_limit_3){
                    OfferListEntity.ContentBean.ProductListBean bean = (OfferListEntity.ContentBean.ProductListBean)view.getTag(R.id.item_key_status);
                    if(bean.getFather().getExpiredMinSelect().equals(bean.getFather().getFather().getExpiredMin().get(2)))
                        return;
                    else {
                        bean.getFather().setExpiredMinSelect(bean.getFather().getFather().getExpiredMin().get(2));
                    }
                }
                adapter.notifyDataSetChanged();
            }
        });
        mListView.setAdapter(adapter);
        baseback.setVisibility(View.VISIBLE);
        initHeadView();
        requestOrderList(0);
    }

    void initView(){
        setContentView(R.layout.activity_list_minus);
        ll_hint = findViewById(R.id.ll_hint);
        iv_offer_hint_close = findViewById(R.id.iv_offer_hint_close);
        tv_offer_hint = (TextView) findViewById(R.id.tv_offer_hint);
        iv_offer_hint_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ll_hint.setVisibility(View.GONE);
            }
        });


        mListView = (LoadMoreListView)findViewById(R.id.listview);
        basetitle.setText("抢单");
        rightbtn.setText("历史抢单");

        rightbtn.setVisibility(View.VISIBLE);
        rightbtn.setOnClickListener(this);
        vException = findViewById(R.id.v_exception);
        mainView = findViewById(R.id.fragment_ptr_home_ptr_frame);
        initException();
    }

    public void openDialog(final OfferListEntity.ContentBean.ProductListBean goods) {

        final Dialog dialog = new Dialog(this, R.style.no_title_dialog);

        dialog.setContentView(R.layout.dialog_cart_add);
        ImageView ivAdd = (ImageView) dialog.findViewById(R.id.iv_add);
        ImageView ivRemove = (ImageView) dialog.findViewById(R.id.iv_remove);

        final EditText ed = (EditText) dialog.findViewById(R.id.ed_price);

        ed.setText(/*FormatUtil.subZeroAndDot*/FormatUtil.subZeroAndDot(goods.getPriceNow() + ""));
        ed.setSelection(ed.length());
        PointerInputFilter cashierInputFilter = new PointerInputFilter();
        cashierInputFilter.MAX_VALUE = 9999.99;
        ed.setFilters(new InputFilter[]{cashierInputFilter});

        final BigDecimal unit = getUnit(goods.getUnitPrice());


        ivAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String s = ed.getText().toString();
                if(s==null||"".equals(s))
                    return;

                double price;
                try {
                    price = Double.valueOf(s);
                }catch (Exception e){
                    return;
                }
                if(unit.add(new BigDecimal(price)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue()>9999.99) {
                    price = 9999.99;
                    toast("价格不能大于9999.99");
                    ed.setText(FormatUtil.subZeroAndDot("" + (new BigDecimal(price)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()));
                }
                else
                    ed.setText(FormatUtil.subZeroAndDot(""+unit.add(new BigDecimal(price)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue()));
                ed.setText(FormatUtil.subZeroAndDot(""+unit.add(new BigDecimal(price)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue()));
                ed.setSelection(ed.length());
            }
        });
        ivRemove.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String s = ed.getText().toString();
                if(s==null||"".equals(s))
                    return;

                double price;
                try {
                    price = Double.valueOf(s);
                }catch (Exception e){
                    return;
                }
                if((new BigDecimal(price).subtract(unit)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue()<=0) {
                    ed.setText(FormatUtil.subZeroAndDot("" + (new BigDecimal(price)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()));
                    toast("价格不能小于0");
                }
                else
                    ed.setText(FormatUtil.subZeroAndDot(""+(new BigDecimal(price).subtract(unit)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue()));
                ed.setSelection(ed.length());
            }
        });
        dialog.findViewById(R.id.negativeButton).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm.isActive()) {
                    imm.hideSoftInputFromWindow(ed.getApplicationWindowToken(), 0);
                }
                dialog.dismiss();
            }
        });

        dialog.findViewById(R.id.positiveButton).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String s = ed.getText().toString();
                if(s==null||"".equals(s))
                    return;
                try {
                    if (Double.valueOf(s) == 0) {
                        toast("价格不能小于0");
                        //goods.setPriceNow(0.00);
                        return;
                    }
                    if (Double.valueOf(s) > 9999.99) {
                        toast("价格不能大于9999.99");
                        return;
                        //goods.setPriceNow(9999.99);
                    }
                    goods.setPriceNow(Double.valueOf(s));
                }catch (Exception e){
                    toast("请检查输入");
                    return;
                }
                adapter.notifyDataSetChanged();
                InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm.isActive()) {
                    imm.hideSoftInputFromWindow(ed.getApplicationWindowToken(), 0);
                }
                dialog.dismiss();
            }
        });

        dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialogInterface) {

            }
        });

        dialog.show();

    }


    public void initException() {
        tvExceptionDescription = (TextView) vException.findViewById(R.id.tv_exception);
        ivExceptionIcon = (ImageView) vException.findViewById(R.id.iv_exception);
        pb = (ProgressBar) vException.findViewById(R.id.pb);
    }


    public void showMainView() {
        vException.setVisibility(View.GONE);
        mainView.setVisibility(View.VISIBLE);
    }


    public void showExceptionView(int imgSrc, String text, int exceptionType) {
        if (imgSrc > 0) {

        }
        pb.setVisibility(View.GONE);
        vException.setVisibility(View.VISIBLE);
        tvExceptionDescription.setVisibility(View.VISIBLE);
        ivExceptionIcon.setVisibility(View.VISIBLE);
        mainView.setVisibility(View.GONE);

        ivExceptionIcon.setImageResource(imgSrc);
        tvExceptionDescription.setText(text);
        tvExceptionDescription.setTag(exceptionType);
        ivExceptionIcon.setTag(exceptionType);
        tvExceptionDescription.setOnClickListener(this);
        ivExceptionIcon.setOnClickListener(this);
    }
    public void showProgressView() {

        pb.setVisibility(View.VISIBLE);
        vException.setVisibility(View.VISIBLE);
        tvExceptionDescription.setVisibility(View.GONE);
        ivExceptionIcon.setVisibility(View.GONE);
        mainView.setVisibility(View.GONE);
    }


    private PtrMdFrameLayout ptrFrameLayout;
    private PtrHandler ptrHandler = new PtrHandler() {
        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
            return PtrDefaultHandler.checkContentCanBePulledDown(frame, mListView, header);
        }

        @Override
        public void onRefreshBegin(PtrFrameLayout frame) {
            refresh();
        }
    };

    private void initHeadView() {
        ptrFrameLayout = (PtrMdFrameLayout) findViewById(R.id.fragment_ptr_home_ptr_frame);
        ptrFrameLayout.setPtrHandler(ptrHandler);
    }

    boolean refreshFlag = false;
    public void refresh() {
        mListView.resetNoMore();
        refreshFlag = true;
        requestOrderList(0);
    }

    @Override
    public void onLoadMore() {
        int number = tagPager.getNumber();
        requestOrderList( number + 1);
    }


    public void updateViewStatus(RequestTag requestTag) {
        ptrFrameLayout.refreshComplete();
        if (tagPager.isLast()) {
            mListView.noMore();
        } else {
            mListView.stopLoadMore();
        }
    }

    private List<OfferListEntity.SupplyGiveupReasonBean> supplyGiveupReason;

    OnRequestListener<OfferListEntity> onRequestListener = new OnRequestListener<OfferListEntity>() {
        @Override
        public OfferListEntity jsonToObj(String responseStr) {
            return new Gson().fromJson(responseStr, OfferListEntity.class);
        }

        @Override
        public void onFail(int failCode, Object arg, Object tag) {
            RequestTag requestTag = (RequestTag) tag;
            updateViewStatus(requestTag);
            if (requestSucceedCount == 0){
                showExceptionView(R.mipmap.order_no, "网络问题,请点击重试", HttpRequest.FAIL_NET_FAULT);
            }
        }

        @Override
        public void onResponseError(int failCode, Object arg, Object tag) {
            if (requestSucceedCount == 0){
                showExceptionView(R.mipmap.order_no, arg + "", HttpRequest.FAIL_DATA_FAULT);//arg + ",请点击重试"
            }
            RequestTag requestTag = (RequestTag) tag;
            updateViewStatus(requestTag);
        }

        @Override
        public void onStart(Object tag) {
            if (requestSucceedCount == 0){
                showProgressView();
            }
        }

        @Override
        public void onResponse(ResponseEntity<OfferListEntity> response, Object tag) {
            showMainView();
            requestSucceedCount ++;
            RequestTag requestTag = (RequestTag) tag;
            if (requestTag.action == 0) {
                list.clear();
            }
            OfferListEntity orderResponse = response.getResponseElement();
            supplyGiveupReason = orderResponse.getSupplyGiveupReason();

            List<OfferListEntity.ContentBean> content = orderResponse.getContent();
            tagPager.setLast(orderResponse.isLast());
            tagPager.setNumber(orderResponse.getNumber());
            tagPager.setSize(orderResponse.getSize());
            tagPager.setTotalElements(orderResponse.getTotalElements());
            for(int i=0;content!=null&&i<content.size();i++){
                OfferListEntity.ContentBean bean = content.get(i);
                bean.setFather(orderResponse);
                for(int j=0;bean.getProductList()!=null&&j<bean.getProductList().size();j++){
                    bean.getProductList().get(j).setFather(bean);
                    if(j==0){
                        bean.getProductList().get(j).setHeader(true);
                    }
                    if(j==bean.getProductList().size()-1){
                        bean.getProductList().get(j).setFoot(true);
                    }
                }
                list.addAll(bean.getProductList());
            }

            adapter.notifyDataSetChanged();
            adapter.timerStart();
            if(orderResponse.getNumber()==0){
                if(refreshFlag) {
                    mListView.setSelection(0);
                    refreshFlag=false;
                }
            }
            updateViewStatus(requestTag);
            if(list.size()==0){
                showExceptionView(R.mipmap.offer_no, "暂无抢单", HttpRequest.FAIL_DATA_EMPTY);
            }

        }
    };


    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.baseback:
                // 返回上一页
                finish();
                break;
            case R.id.rightbtn:
                Intent intent = new Intent(this, OfferHistoryListActivity.class);
                startActivity(intent);
                break;
                /*
               "cmd": "/order/offer/supplySaveOffer",
                 "parameters": {
                    "id": "报价id",
                    "expiredMin": "超期时间",
                    "productList": [
                      {
                        "id": "商品报价id",
                        "productUnitPrice": "商品价格"
                      },
                      {
                        "id": "商品报价id",
                        "productUnitPrice": "商品价格"
                      }
                    ]
                  }
                * */
        }
    }

    private RequestTag requestTag = new RequestTag();
    public void requestOrderList(int page) {

        RequestEntitySupply<Map<String, String>> entity = new RequestEntitySupply<>();
        Map<String, String> map = new HashMap<>();
        map.put("storeId", BaseApplication.getInstance().getStoreId());

        map.put("pageNumber", page + "");
        map.put("pageSize", "10");

        entity.setCmd(com.epfresh.api.constant.AppSupplyRouterConstant.cmd_store_product_offer_supplyOfferList);
        entity.setParameters(map);
        requestTag.tag = com.epfresh.api.constant.AppSupplyRouterConstant.cmd_store_product_offer_supplyOfferList;
        requestTag.action = page;
        request(entity, requestTag, onRequestListener);
    }

    public class Param{

        /**
         * id : 商品id
         * productUnitPrice : 商品促销场次id
         * versionId : 商品版本
         */

        private String productOfferDetailId;
        private String offerDuration;
        private double price;
        private String reason;

        public String getReason() {
            return reason;
        }

        public void setReason(String reason) {
            this.reason = reason;
        }

        public String getProductOfferDetailId() {
            return productOfferDetailId;
        }

        public void setProductOfferDetailId(String productOfferDetailId) {
            this.productOfferDetailId = productOfferDetailId;
        }

        public String getOfferDuration() {
            return offerDuration;
        }

        public void setOfferDuration(String offerDuration) {
            this.offerDuration = offerDuration;
        }

        public double getPrice() {
            return price;
        }

        public void setPrice(double price) {
            this.price = price;
        }
    }


    public void postSubmit(OfferListEntity.ContentBean bean) {

        RequestEntitySupply<Map<String, Object>> entity = new RequestEntitySupply<>();
        Map<String, Object> map = new HashMap<>();
/*        map.put("id",bean.getId());
        map.put("expiredMin",bean.getExpiredMinSelect());*/
        ArrayList list = new ArrayList();
        for(int i=0;i<bean.getProductList().size();i++){
            if(!bean.getProductList().get(i).isDisabled()){
                Param param = new Param();
                param.setProductOfferDetailId(bean.getProductList().get(i).getProductOfferDetailsId());
                param.setPrice(bean.getProductList().get(i).getPriceNow());
                param.setOfferDuration(bean.getExpiredMinSelect());
                if(bean.getProductList().get(i).getPriceNow()>9999.99){
                    toast("价格不能大于9999.99");
                    return;
                }
                list.add(param);
            }
        }
        map.put("productOfferDetails",list);
/*        if(bean.getProductList().get(0).getPriceNow()>9999.99){
            toast("价格不能大于9999.99");
            return;
        }
        map.put("productOfferDetailId",bean.getProductList().get(0).getProductOfferDetailsId());
        map.put("price",bean.getProductList().get(0).getPriceNow());
        map.put("offerDuration",bean.getExpiredMinSelect());*/
        entity.setCmd(com.epfresh.api.constant.AppSupplyRouterConstant.cmd_store_product_offer_supplySaveOffer);
        entity.setParameters(map);
        request(entity, com.epfresh.api.constant.AppSupplyRouterConstant.cmd_store_product_offer_supplySaveOffer, onCloseSubmitListener);
    }

    OnRequestListener<SaveEntity> onCloseSubmitListener = new OnRequestListener<SaveEntity>() {
        @Override
        public SaveEntity jsonToObj(String responseStr) {
            return new Gson().fromJson(responseStr, SaveEntity.class);
        }

        @Override
        public void onFail(int failCode, Object arg, Object tag) {
            hideProgressDialog();
            toast("网络问题,请点击重试");
            requestOrderList(0);
        }

        @Override
        public void onResponseError(int failCode, Object arg, Object tag) {
            hideProgressDialog();
            toast(arg + "");
            requestOrderList(0);
        }

        @Override
        public void onStart(Object tag) {
            showProgressDialog();
        }

        @Override
        public void onResponse(ResponseEntity<SaveEntity> response, Object tag) {
            hideProgressDialog();
            toast(response.getResponseElement().getMessage());
            requestOrderList(0);

        }
    };


    public void closeSubmit(OfferListEntity.ContentBean.ProductListBean bean,String reason) {
        RequestEntitySupply<Map<String, Object>> entity = new RequestEntitySupply<>();
        Map<String, Object> map = new HashMap<>();
        Param param = new Param();
        param.setReason(reason);
        param.setProductOfferDetailId(bean.getProductOfferDetailsId());
        ArrayList list = new ArrayList();
        list.add(param);
        map.put("productOfferDetails",list);
        entity.setCmd(com.epfresh.api.constant.AppSupplyRouterConstant.cmd_store_product_offer_waiveOffer);
        entity.setParameters(map);
        request(entity, com.epfresh.api.constant.AppSupplyRouterConstant.cmd_store_product_offer_waiveOffer, onSubmitListener);
    }

    OnRequestListener<SaveEntity> onSubmitListener = new OnRequestListener<SaveEntity>() {
        @Override
        public SaveEntity jsonToObj(String responseStr) {
            return new Gson().fromJson(responseStr, SaveEntity.class);
        }

        @Override
        public void onFail(int failCode, Object arg, Object tag) {
            hideProgressDialog();
            toast("网络问题,请点击重试");
        }

        @Override
        public void onResponseError(int failCode, Object arg, Object tag) {
            hideProgressDialog();
            toast(arg + "");
        }

        @Override
        public void onStart(Object tag) {
            showProgressDialog();
        }

        @Override
        public void onResponse(ResponseEntity<SaveEntity> response, Object tag) {
            hideProgressDialog();
            toast("已放弃");
            requestOrderList(0);
        }
    };

    OfferReasonListDialog offerReasonListDialog;

    private void openReasonDialog(final OfferListEntity.ContentBean.ProductListBean bean) {
        if (supplyGiveupReason == null || supplyGiveupReason.size() == 0) {
            return;
        }
        //if (offerReasonListDialog == null) {
            offerReasonListDialog = new OfferReasonListDialog(this);
            offerReasonListDialog.setAnim(false);
            offerReasonListDialog.setOnSelectedListener(new OfferReasonListDialog.OnSelectedListener() {
                @Override
                public void onSelected(OfferListEntity.SupplyGiveupReasonBean item) {
                    if (item != null) {
                        offerReasonListDialog.dismiss();
                        Log.e("___dia_________after",""+bean.getId());

                        closeSubmit(bean,item.getId());
                    }
                }
            });
        //}
        offerReasonListDialog.show(supplyGiveupReason);
    }


}
